class Solution {
public:
    class cmp{
    public:
        bool operator()(pair<char,int>& a,pair<char,int>& b){
            return a.second < b.second;
        }
    };    
                                        
    string longestDiverseString(int a, int b, int c) {
                            priority_queue<pair<char,int>,vector<pair<char,int>>,cmp> pri_que;
        pri_que.push({'a',a});
        pri_que.push({'b',b});
        pri_que.push({'c',c});
        
        string s = "";
        int n = 0;
        
        while(1){
            auto p = pri_que.top();
            pri_que.pop();
            if(p.second <= 0) break;
            
            if(n >= 2 && s[n-1] == p.first && s[n-2] == p.first){
                auto q = pri_que.top();
                pri_que.pop();
                if(q.second <= 0) break;
                
                s += q.first;
                q.second--;
                pri_que.push(q);
            }else{
                s += p.first;
                p.second--;
            }
            pri_que.push(p);
            n++;
        }
        
        return s;
    }
};
